package dm.ass1;

import java.io.IOException;

import org.apache.hadoop.io.LongWritable;
import org.apache.hadoop.io.Text;
import org.apache.hadoop.mapreduce.Mapper;

import dm.ass1.io.RatingWritable;

public class ProfileMapper extends Mapper<LongWritable, Text, Text, RatingWritable> {

	@Override
	protected void map(LongWritable key, Text value, Context context) throws IOException, InterruptedException {
		String[] record = value.toString().split("\\W+");
		int user = Integer.parseInt(record[0]);
		int item = Integer.parseInt(record[1]);
		int rating = Integer.parseInt(record[2]);
		
		Text keyUser = new Text(ProfilingDriver.PREFIX_USER + user);
		Text keyItem = new Text(ProfilingDriver.PREFIX_ITEM + item);
		RatingWritable ratingRecord = new RatingWritable(user, item, rating);
		context.write(keyUser, ratingRecord);
		context.write(keyItem, ratingRecord);
	}

}
